import {
  createRouter,
  createWebHashHistory
} from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [{
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/RegisterView.vue')
  },
  {
    path: '/goods',
    name: 'goods',
    component: () => import('../views/GoodsView.vue')
  },
  {
    path: '/orders',
    name: 'orders',
    component: () => import('../views/OrderView.vue')
  },
  // {
  //   path: '/test',
  //   name: 'test',
  //   component: () => import( '../views/TestView.vue')
  // },

  {
    path: '/404',
    name: 'not_found',
    component: () => import('../views/404View.vue')
  },
  {
    path: '/:pathMatch(.*)',
    redirect: '/404'
  },

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {

  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = 'HChat'
  }
  next()
})

export default router